package com.yhy.server.controller;

import com.yhy.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
        return tanhuaService.todayBest();
    }

    @GetMapping("/recommendation")
    public ResponseEntity recommendation(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer pagesize){
        return tanhuaService.recommendation(page,pagesize);
    }
    /**
     *  佳人信息
     *
     *  接口路径：GET /tanhua/:id/personalInfo
     *
     *  参数:
     *      id: 用户id
     *
     *  返回值: pageResult<TodayBest>
     *
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId){
        return tanhuaService.personalInfo(userId);
    }

    /**
     * 查询陌生人问题
     *
     * 接口路径：GET/tanhua/strangerQuestions
     *
     * 参数:
     *      Query:
     *      userId: 用户id
     *
     * 返回值: String 陌生人问题
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        return tanhuaService.strangerQuestions(userId);
    }

    /**
     * 回复陌生人问题
     *
     * 接口路径：POST/tanhua/strangerQuestions
     *
     * 参数:
     *      Body:
     *      userId: 用户id (好友id)
     *      reply: 回复
     *
     * 返回值: null
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity answerStrangerQuestion(@RequestBody Map map){
        Integer id = (Integer) map.get("userId");
        String reply = (String) map.get("reply");
        Long userId = Long.valueOf(id);
        return tanhuaService.answerStrangerQuestion(userId,reply);
    }

    /**
     * 搜附近
     *
     * 接口路径：GET/tanhua/search
     *
     * 请求参数: Query
     *      gender: 性别
     *      distance:距离
     *
     * 返回值: List<NearUserVo>
     */
    @GetMapping("/search")
    public ResponseEntity search(String gender,String distance){
        return tanhuaService.searchNear(gender,distance);
    }

}
